﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class XF_ZDJDJLControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        DropDownList DropDownList1;
        CustomGridView CustomGridList1;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            if (!base.Page.IsPostBack)
            {
                Bind();
                QSDataDLL();
            }
            Button btnsearch = (Button)FindControl("btnSeach");
            btnsearch.Click += new EventHandler(Go_Search);
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
        }
        protected void InitControl()
        {
            DropDownList1 = (DropDownList)FindControl("DropDownList1");
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
        }
        protected void Go_Search(object sender, EventArgs e)
        {
            Bind();
        }
        protected void Bind()
        {

            DataTable dt = GetXFXX();
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataBind();
        }
        protected DataTable GetXFXX()
        {
            string sql = @"Select (Select 区属 From Zs_Project Where Id=t.pnid) 区属,
    (Select 项目名称 From Zs_Project Where Id=t.pnid) 项目名称,
    (Select 立项号 From Zs_Project Where Id=t.pnid) 立项号,
    (Select 征收实施单位 From Zs_Project Where Id=t.pnid) 征收实施单位,
    t.信访人姓名,t.信访时间,t.信访类别,t.现住址,t.包案领导,t.id zid,t.pnid 
    From zs_xinfangzd t where 1=1 ";
            string sqlWhere = string.Empty;
            TextBox TextBox1 = (TextBox)FindControl("TextBox1");
            TextBox TextBox2 = (TextBox)FindControl("TextBox2");
            TextBox TextBox3 = (TextBox)FindControl("TextBox3");
            TextBox TextBox4 = (TextBox)FindControl("TextBox4");
            TextBox TextBox5 = (TextBox)FindControl("TextBox5");

            string strXMMC = TextBox1.Text.Trim();
            string strSSDW = TextBox2.Text.Trim();
            string strLXH = TextBox3.Text.Trim();
            string strXFR = TextBox4.Text.Trim();
            string strBALD = TextBox5.Text.Trim();
            string strQS = DropDownList1.SelectedValue;
            if (!string.IsNullOrEmpty(strXMMC))
            {
                sqlWhere += " and t.pnid in(select id from zs_project where 项目名称 like '%" + strXMMC + "%')";
            }
            if (!string.IsNullOrEmpty(strSSDW))
            {
                sqlWhere += " and t.pnid in (select id from zs_project where 征收实施单位 like '%" + strSSDW + "%')";
            }
            if (!string.IsNullOrEmpty(strLXH))
            {
                sqlWhere += " and t.pnid in (select id from zs_project where 立项号 like '%" + strLXH + "%')";
            }
            if (!string.IsNullOrEmpty(strXFR))
            {
                sqlWhere += " and t.信访人姓名 like '%" + strXFR + "%'";
            }
            if (!string.IsNullOrEmpty(strBALD))
            {
                sqlWhere += " and t.包案领导 like '%" + strBALD + "%'";
            }
            if (!string.IsNullOrEmpty(strQS))
            {
                sqlWhere += " and t.pnid in (select id from zs_project where 区属='" + strQS + "')";
            }
            if (_EluZSDataProvider.IsQZSBM(userid))
            {
                sqlWhere += @" and t.pnid in (select id from zs_project where 区属 in(select keyname from zs_params where name='区属'and (Select tt.ROLENAME  From zs_USER_IN_ROLE t Join  zs_Role tt  On  t.roleid=tt.id
Where  t.userid Like '%" + userid + "%') Like '%'||keyname||'%'))";
            }
            sql += sqlWhere;
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            return dt;
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected string GetSqlWhere()
        {
            string sqlWhere = string.Empty;
            TextBox TextBox1 = (TextBox)FindControl("TextBox1");
            TextBox TextBox2 = (TextBox)FindControl("TextBox2");
            TextBox TextBox3 = (TextBox)FindControl("TextBox3");
            TextBox TextBox4 = (TextBox)FindControl("TextBox4");
            TextBox TextBox5 = (TextBox)FindControl("TextBox5");

            string strXMMC = TextBox1.Text.Trim();
            string strSSDW = TextBox2.Text.Trim();
            string strLXH = TextBox3.Text.Trim();
            string strXFR = TextBox4.Text.Trim();
            string strBALD = TextBox5.Text.Trim();
            string strQS = DropDownList1.SelectedValue;
            if (!string.IsNullOrEmpty(strXMMC))
            {
                sqlWhere += " and p1.项目名称 like '%" + strXMMC + "%'";
            }
            if (!string.IsNullOrEmpty(strSSDW))
            {
                sqlWhere += " and p1.征收实施单位 like '%" + strSSDW + "%'";
            }
            if (!string.IsNullOrEmpty(strLXH))
            {
                sqlWhere += " and p1.立项号 like '%" + strLXH + "%'";
            }
            if (!string.IsNullOrEmpty(strXFR))
            {
                sqlWhere += " and z1.信访人姓名 like '%" + strXFR + "%'";
            }
            if (!string.IsNullOrEmpty(strBALD))
            {
                sqlWhere += " and z1.包案领导 like '%" + strBALD + "%'";
            }
            if (!string.IsNullOrEmpty(strQS))
            {
                sqlWhere += " and p1.区属='" + strQS + "'";
            }
            if (_EluZSDataProvider.IsQZSBM(userid))
            {
                sqlWhere += @" and p1.区属 in(select keyname from zs_params where name='区属'and (Select tt.ROLENAME  From zs_USER_IN_ROLE t Join  zs_Role tt  On  t.roleid=tt.id
Where  t.userid Like '%" + userid + "%') Like '%'||keyname||'%')";
            }
            return sqlWhere;
        }
        protected void QSDataDLL()
        {
            //List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("区属");
            //EluZSProvider.Params item = new EluZSProvider.Params();
            // _params.Insert(0, item);
            DataTable dt = _EluZSDataProvider.GetParamYB("区属", GetWhere());
            DropDownList1.DataSource = dt;
            DropDownList1.DataValueField = "keyname";
            DropDownList1.DataTextField = "keyname";
            DropDownList1.DataBind();
        }

        protected string GetWhere()
        {
            string sqlWhere = string.Empty;
            if (_EluZSDataProvider.IsQZSBM(userid))
            {
                sqlWhere += @" and (Select tt.ROLENAME  From zs_USER_IN_ROLE t Join  zs_Role tt  On  t.roleid=tt.id
Where  t.userid Like '%" + userid + "%') Like '%'||keyname||'%' ";
            }
            return sqlWhere;
        }
    }
}


